package com.calvin.lingting.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import com.calvin.lib.json.JSONArray;
import com.calvin.lingting.R;

public class DwonloadBookListViewAdapter extends BaseAdapter {
    JSONArray mBookList;
    Context mContext;
    AbsListView.LayoutParams mLayoutParams;

    public DwonloadBookListViewAdapter(Context context, JSONArray bookList) {
        mContext = context;
        mBookList = bookList;
        mBookList = mBookList == null ? new JSONArray() : mBookList;
        float itemHeight = mContext.getResources().getDimension(R.dimen.d_book_item_size);
        mLayoutParams = new AbsListView.LayoutParams(-1, (int) itemHeight);
    }

    public JSONArray getBookList() {
        return mBookList;
    }

    public void setBookList(JSONArray mBookList) {
        this.mBookList = mBookList;
    }

    @Override
    public int getCount() {
        return mBookList.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.list_download_item, null);
        }
//        JSONObject bookInfo = mBookList.getJSONObject(position);
//        CUtils.cast(convertView.findViewById(R.id.book_name), TextView.class).setText(bookInfo.getStringValue(LrtsConfig.K_NAME));
//        String tmp = MainActivity.sharedCurrent().getResources().getString(R.string.s_author);
//        CUtils.cast(convertView.findViewById(R.id.book_author), TextView.class).setText(tmp + bookInfo.getStringValue(LrtsConfig.K_AUTHOR));
//        tmp = MainActivity.sharedCurrent().getResources().getString(R.string.s_guser);
//        CUtils.cast(convertView.findViewById(R.id.book_guser), TextView.class).setText(tmp + bookInfo.getStringValue(LrtsConfig.K_G_USER));
//        Lrts.shared().setBookPhoto(CUtils.cast(convertView.findViewById(R.id.book_photo), ImageView.class), bookInfo.getStringValue(LrtsConfig.K_PHOTO));
//        convertView.setLayoutParams(mLayoutParams);
        return convertView;
    }
}
